package cn.cvs.servlet;

import cn.cvs.dao.FruitIdDao;
import cn.cvs.pojo.Fruit;
import cn.cvs.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/SelectList")
public class SelectList extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<Fruit> fruit = sqlSession.getMapper(FruitIdDao.class).selectByFruit();
        req.getSession().setAttribute("list",fruit);
        MyBatisUtil.closeSqlSession(sqlSession);
        req.getRequestDispatcher("list.jsp").forward(req,resp);
    }
}
